package com.simple.cms.controller.admin;

import com.baomidou.mybatisplus.plugins.Page;
import com.simple.cms.biz.IProductService;
import com.simple.cms.common.result.CommonResult;
import com.simple.cms.common.result.PageListResult;
import com.simple.cms.model.request.ProductForm;
import com.simple.cms.model.response.ProductBaseInfo;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 产品表 前端控制器
 * </p>
 *
 * @author kin
 * @since 2017-07-17
 */
@RestController
@RequestMapping("/admin/api/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public CommonResult add(ProductForm productForm) {
        String t = (String) SecurityUtils.getSubject().getPrincipal();
        //productService.addProduct(productForm);
        return new CommonResult();
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public PageListResult<ProductBaseInfo> list(@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize) {
        Page<ProductBaseInfo> productInfoPage = productService.getProductList(new Page<>(pageNum, pageSize));
        return new PageListResult<>(productInfoPage.getRecords(), productInfoPage);
    }

}
